package com.liyu.rabbit.factory;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 作者: 李誉
 * 时间: 2022-03-03 15:06
 * 描述: 工厂
 */
public class  RabbitFactory {
    private RabbitFactory(){}

    /**
     * 创建消息信道
     * @return 信道
     */
    public static Channel createNewChannel() throws IOException, TimeoutException {
        // 1、创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        // 2、设置连接信息
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");


        // 3、创建连接
        Connection connection = connectionFactory.newConnection();
        // 4、获得信道
        Channel channel = connection.createChannel();
        return channel;
    }
}
